#pragma once

#include <ostream>
#include <sstream>
#include <tuple>
#include <set>

using namespace std;

template<typename G>
void printGraph(ostream &out, const G &graph)
{
  out << "graph graph1 {" << endl; 
  int nodeCount = graph.countNodes();

  // arestas já marcadas
  set<tuple<int,int>> marked;

  for (int i = 0; i < nodeCount; i++) {
    stringstream ss;
    ss << "node" << i; 
    out << "  " << ss.str() << " [label=\"" << graph.getNodeValue(i) << "\"];" << endl; 

    vector<int> adjacents = graph.getAdjacentNodes(i);

    for (int a: adjacents) {

      if (marked.find(make_tuple(i,a)) != marked.end()) {
        continue;
      }

      marked.insert(make_tuple(i,a));
      marked.insert(make_tuple(a,i));

      out << "  " << "node" << i << " -- " << "node" << a << " [label=\"" << graph.getEdgeValue(i,a) << "\"];" << endl;
    }
  }

  out << "}" << endl;
}
